package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by AD on 2016/5/12.
 */
@HttpInlet(Conn.INLET_GET_INTEGRAL_LIST)
public class GetIntegralList extends JTAsyGet<GetIntegralList.Info> {
    public String token = JTApplication.jtPreferences.readToken();
    public String userId = JTApplication.jtPreferences.readUserID();
    public String date;
    public String type;//1获取   2消费
    public String flag;//1定向   2通用



    public GetIntegralList(AsyCallBack<Info> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected Info parser(JSONObject object) {
        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        JSONObject body = apiTYF.optJSONObject("body");

        Info info = new Info();

        info.msg = head.optString("msg");

        info.code = head.optString("code");

if(head.optString("msg").equals("000")) {
    JSONArray array = body.optJSONArray("list");

    if (array.length() > 0) {
        for (int i = 0; i < array.length(); i++) {
            try {
                JSONObject obj_integral = array.getJSONObject(i);
                IntegralList integrallist = new IntegralList();
                integrallist.id = obj_integral.optString("id");
                integrallist.date = obj_integral.optString("date");
                integrallist.describe = obj_integral.optString("state");
                integrallist.score = obj_integral.optString("score");
                info.integralLists.add(integrallist);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

    }
}else {
    TOAST = "暂无记录";
}

        return info;
    }

    public static class Info{
        public String msg;
        public String code;
        public List<IntegralList> integralLists = new ArrayList<>();
    }
    public static class IntegralList implements Serializable{
        public String id;
        public String date;
        public String describe;
        public String score;
    }
}
